from fasc_api.client.service_client import ServiceClient
from fasc_api.client.user_client import UserClient
from fasc_api.exception.exceptions import ClientException
from fasc_api.exception.exceptions import ServerException

from init_demo_data import InitDemoData
api_client = InitDemoData.api_client
access_token = ServiceClient.get_access_token_value(api_client)
api_client.set_access_token(access_token)


# 添加个人用户
def add_user_demo():
    try:
        data = {
            # 个人用户在应用中的唯一标识
            'clientUserId': InitDemoData.clientUserId,
            'clientUserName': '个人用户别名',
        }
        res = UserClient.add(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 更新个人用户
def update_user_demo():
    try:
        data = {
            # 法大大平台为该用户在该应用appId范围内分配的唯一标识
            'openUserId': InitDemoData.openUserId,
            'clientUserId': '用户在应用系统中的唯一标识',
            'clientUserName': '个人用户别名',
        }
        res = UserClient.update(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 删除个人用户
def delete_user_demo():
    try:
        data = {
            # 法大大平台为该用户在该应用appId范围内分配的唯一标识
            'openUserId': InitDemoData.openUserId
        }
        res = UserClient.delete(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 禁用个人用户
def disable_user_demo():
    try:
        data = {
            # 法大大平台为该用户在该应用appId范围内分配的唯一标识
            'openUserId': InitDemoData.openUserId
        }
        res = UserClient.disable(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 恢复个人用户
def enable_user_demo():
    try:
        data = {
            # 法大大平台为该用户在该应用appId范围内分配的唯一标识
            'openUserId': InitDemoData.openUserId
        }
        res = UserClient.enable(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 解绑个人用户账号
def unbind_user_demo():
    try:
        data = {
            # 法大大平台为该用户在该应用appId范围内分配的唯一标识
            'openUserId': InitDemoData.openUserId
        }
        res = UserClient.unbind(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 获取个人用户授权链接
def get_auth_url_user_demo():
    try:
        data = {
            # 法大大平台为该用户在该应用appId范围内分配的唯一标识
            'openUserId': InitDemoData.openUserId,
            'userIdentInfo': {
                'userName': '个人用户真实姓名',
                'identType': '证件类型 ：id_card: 身份证 , passport: 护照 , hk_macao: 港澳居民来往内地通行证 , taiwan: 台湾居民来往大陆通行证, 只有携带这个参数，identNo参数才有效。',
                'identNo': '证件号'
            },
            'userInfoExtend': {
                'bankAccountNo': '个人银行账户号',
                'mobile': '个人实名手机号'
            },
            'identInfoMatch': '是否需要匹配个人身份信息一致：True/False',
            'requestAuthScope': ['ident_info', 'signtask_init','resource_for_sign'],
            'redirectUrl': '重定向地址'
        }
        res = UserClient.get_auth_url(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 查询个人用户基本信息
def get_detail_user_demo():
    try:
        data = {
            # 法大大平台为该用户在该应用appId范围内分配的唯一标识
            'openUserId': InitDemoData.openUserId
        }
        res = UserClient.get_detail(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 获取个人用户身份信息
def get_identity_info_user_demo():
    try:
        data = {
            # 法大大平台为该用户在该应用appId范围内分配的唯一标识
            'openUserId': InitDemoData.openUserId
        }
        res = UserClient.get_identity_info(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

if __name__ == '__main__':
    add_user_demo()
    update_user_demo()
    delete_user_demo()
    disable_user_demo()
    enable_user_demo()
    unbind_user_demo()
    get_auth_url_user_demo()
    get_detail_user_demo()
    get_identity_info_user_demo()



